//
//  PhonePWDLogin.swift
//  DKE-Album
//
//  Created by 杨东宝 on 2020/5/25.
//  Copyright © 2020 杨东宝. All rights reserved.
//

import UIKit

class PhonePWDLogin: UIView {
    //MARK:-账号密码登录
    lazy var tipLabel1: UILabel = {
        let label = UILabel()
        label.text = "账号密码登录"
        label.textColor = hexColor(0x333333,0xA7A7B3)
        label.font = DIMENSION_FONT_OF_SIZE(30)
        addSubview(label)
        return label
    }()
    //MARK:-账号提示
    lazy var phoneLabel: UILabel = {
        let label = UILabel()
        label.text = "账   号"
        label.textColor = hexColor(0x999999,0xA7A7B3)
        label.font = DIMENSION_FONT_OF_SIZE(18)
        addSubview(label)
        return label
    }()
    //MARK:-密码提示
    lazy var pwdLabel: UILabel = {
        let label = UILabel()
        label.text = "密   码"
        label.textColor = hexColor(0x999999,0xA7A7B3)
        label.font = DIMENSION_FONT_OF_SIZE(18)
        addSubview(label)
        return label
    }()
    //MARK:-手机号输入框
    lazy var phoneTextField: UITextField = {
        let field = UITextField()
        field.placeholder = "请输入手机号"
        field.textColor = hexColor(0x666666,0xA7A7B3)
        field.font = DIMENSION_FONT_OF_SIZE(18)
        field.keyboardType = .phonePad
        field.addTarget(self, action: #selector(textValueChanged), for: .editingChanged)
        addSubview(field)
        return field
    }()
    //MARK:-密码输入框
    lazy var pwdTextField: UITextField = {
        let field = UITextField()
        field.placeholder = "请输入密码"
        field.textColor = hexColor(0x666666,0xA7A7B3)
        field.font = DIMENSION_FONT_OF_SIZE(18)
        field.isSecureTextEntry = true;
        field.addTarget(self, action: #selector(textValueChanged), for: .editingChanged)
        addSubview(field)
        return field
    }()
    //MARK:-分割线
    lazy var linView: UIView = {
        let lin = UIView()
        lin.backgroundColor = hexColor(0xD8D8D8,0xA7A7B3)
        addSubview(lin)
        return lin
    }()
    //MARK:-分割线
    lazy var linView1: UIView = {
        let lin = UIView()
        lin.backgroundColor = hexColor(0xD8D8D8,0xA7A7B3)
        addSubview(lin)
        return lin
    }()
    //MARK:-登录按钮
    lazy var loginBtn: UIButton = {
        let btn = UIButton.init(type: .custom)
        btn.setTitle("登录", for: .normal)
        btn.setTitleColor(HexRGB(0xffffff), for: .normal)
        btn.titleLabel?.font = DIMENSION_FONT_OF_SIZE(18)
        btn.layer.cornerRadius = DIMENSION_VALUE(20)
        btn.layer.masksToBounds = true
        btn.setBackgroundColor(HexRGB(0xD8D8D8), forState: .disabled)
        btn.setBackgroundColor(HexRGB(0x8CC56C), forState: .normal)
        btn.isEnabled = false
        btn.addTarget(self, action: #selector(loginrBtn(_ :)), for: .touchUpInside)
        addSubview(btn)
        return btn
    }()
 

    override init(frame: CGRect) {
        super.init(frame: frame)
        //MARK:-添加控件
        addSubView()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    
    //MARK:-添加控件
    func addSubView() {
        
        tipLabel1.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(DIMENSION_VALUE(41))
            make.height.equalTo(DIMENSION_VALUE(42))
            make.top.equalToSuperview().offset(DIMENSION_VALUE(10))
        }
        
        phoneLabel.snp.makeConstraints { (make) in
            make.left.equalTo(tipLabel1.snp.left)
            make.width.equalTo(DIMENSION_VALUE(54))
            make.height.equalTo(DIMENSION_VALUE(25))
            make.centerY.equalTo(phoneTextField.snp.centerY)
        }
        
        phoneTextField.snp.makeConstraints { (make) in
            make.left.equalTo(phoneLabel.snp.right).offset(DIMENSION_VALUE(20))
            make.right.equalToSuperview().offset(DIMENSION_VALUE(-41))
            make.height.equalTo(DIMENSION_VALUE(54))
            make.top.equalTo(tipLabel1.snp.bottom).offset(DIMENSION_VALUE(58))
        }
        
        linView.snp.makeConstraints { (make) in
            make.left.equalTo(tipLabel1.snp.left)
            make.right.equalToSuperview().offset(DIMENSION_VALUE(-41))
            make.height.equalTo(DIMENSION_VALUE(1))
            make.top.equalTo(phoneTextField.snp.bottom)
        }
        
        
        pwdLabel.snp.makeConstraints { (make) in
            make.left.equalTo(tipLabel1.snp.left)
            make.width.equalTo(DIMENSION_VALUE(54))
            make.height.equalTo(DIMENSION_VALUE(25))
            make.centerY.equalTo(pwdTextField.snp.centerY)
        }
        
        
        pwdTextField.snp.makeConstraints { (make) in
            make.left.equalTo(pwdLabel.snp.right).offset(DIMENSION_VALUE(20))
            make.right.equalToSuperview().offset(DIMENSION_VALUE(-95))
            make.height.equalTo(DIMENSION_VALUE(54))
            make.top.equalTo(linView.snp.bottom)
        }
        
        
        linView1.snp.makeConstraints { (make) in
            make.left.equalTo(tipLabel1.snp.left)
            make.right.equalToSuperview().offset(DIMENSION_VALUE(-41))
            make.height.equalTo(DIMENSION_VALUE(1))
            make.top.equalTo(pwdTextField.snp.bottom)
        }
        
        
        loginBtn.snp.makeConstraints { (make) in
            make.left.equalTo(tipLabel1.snp.left)
            make.right.equalToSuperview().offset(DIMENSION_VALUE(-41))
            make.height.equalTo(DIMENSION_VALUE(40))
            make.top.equalTo(linView1.snp.bottom).offset(DIMENSION_VALUE(36))
        }
        
    }
    
}

extension PhonePWDLogin{
    
    //MARK:-登录按钮点击事件
    @objc func loginrBtn(_ btn:UIButton) {
        
        DebugLog("登录点击")

        
    }
    
}
extension PhonePWDLogin{
    
    //MARK:-监听输入
    @objc func textValueChanged() {
        
        if !(phoneTextField.text == "") && !(pwdTextField.text == ""){
            
            loginBtn.isEnabled = true
            
        }else{
            
            loginBtn.isEnabled = false
            
        }
    }
    
}
